//
//  SideContentViewController.m
//  恒记
//
//  Created by can on 16/5/5.
//  Copyright © 2016年 can. All rights reserved.
//

#import "SideContentViewController.h"
#import "SideContentTableViewCell.h"
#import "AboutUsViewController.h"
#import "BudgetToRemindViewController.h"
#import "SetPasswordViewController.h"
#import "PasswordSwitchViewController.h"
#import "FeedbackViewController.h"

@interface SideContentViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *dataSource;
@property (nonatomic, strong) NSArray *images;

@end

@implementation SideContentViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    /**< 测试 */
//    UIImageView *backImage = [[UIImageView alloc] initWithFrame:self.view.bounds];
//    backImage.center = self.view.center;
//    backImage.image = [UIImage imageNamed:@"ii"];
//    [self.view addSubview:backImage];
    self.view.backgroundColor = [UIColor whiteColor];
    
    UITextField *headerTextField = [[UITextField alloc] initWithFrame:CRM(0.4 * P_width, 0, 0.6 * P_width, P_height * 0.1)];
    headerTextField.backgroundColor = [UIColor whiteColor];
    headerTextField.text = @"设置";
    headerTextField.textAlignment = NSTextAlignmentCenter;
    headerTextField.font = [UIFont systemFontOfSize:20];
    [self.view addSubview:headerTextField];
    
    
    _tableView = [[UITableView alloc] initWithFrame:CRM(0.4 * PROPORTION_W * SCREEN_WIDTH, SCREEN_HEIGHT * PROPORTION_H * 0.1, 0.6 * PROPORTION_W * SCREEN_WIDTH, SCREEN_HEIGHT * PROPORTION_H * 0.75)];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.rowHeight = SCREEN_HEIGHT * PROPORTION_H / 10;
    _tableView.backgroundColor = [UIColor yellowColor];
//偏移  开关
    self.automaticallyAdjustsScrollViewInsets = NO;
//    self.tableView.contentInset = UIEdgeInsetsMake(- 20 * PROPORTION_H, 0, 0, 0);
    self.tableView.scrollEnabled = NO;
    _tableView.separatorStyle = NO;
    [self.view addSubview:self.tableView];
    
    UIView *footView = [[UIView alloc] initWithFrame:CGRectMake(0, P_height * 0.85, P_width, P_height / 20)];
    footView.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:footView];
    
    UIButton *clearButton = [UIButton buttonWithType:UIButtonTypeSystem];
    clearButton.backgroundColor = [UIColor whiteColor];
    clearButton.frame = CRM(0.4 * P_width, 0.9 * P_height, 0.6 * P_width, P_height * 0.1);
    [clearButton setTitle:@"清除数据" forState:UIControlStateNormal];
    clearButton.titleLabel.textAlignment = NSTextAlignmentCenter;
    [clearButton addTarget:self action:@selector(clearInfo) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:clearButton];
    
//    [self.tableView reloadData];
}
//分区有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}
//分区
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return SCREEN_HEIGHT * PROPORTION_H / 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    _dataSource = @[@[@"首页",@"开启预算提醒"],@[@"设置密码",@"是否开启密码"],@[@"意见反馈",@"关于我们"]];
    _images = @[@"首页4", @"提醒4", @"设置密码4", @"开关4", @"意见反馈4", @"关于我们4"];
    static NSString *cellIdentifer = @"myCell";
    SideContentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
    if (!cell) {
        cell = [[SideContentTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifer];
    }
    cell.mainImage.image = [UIImage imageNamed:_images[indexPath.row]];
    cell.titleLabel.text = _dataSource[indexPath.section][indexPath.row];
    return cell;
}

#pragma mark -- UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    //取消 cell 选中的颜色
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    NSInteger number = indexPath.section * 2 + indexPath.row;
    
    switch (number) {
        case 0:
            [self backHomePage];
            break;
        case 1:
            [self BudgetToRemind];
            break;
        case 2:
            [self setPassword];
            break;
        case 3:
            [self passwordSwitch];
            break;
        case 4:
            [self feedback];
            break;
        case 5:
            [self aboutUs];
            break;
        
        default:
            break;
    }
    
}

- (void)backHomePage {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)BudgetToRemind {
    BudgetToRemindViewController *budgetToRemindVC = [[BudgetToRemindViewController alloc] init];
    [self.navigationController pushViewController:budgetToRemindVC animated:YES];
}

- (void)setPassword {
    SetPasswordViewController *setPasswordVC = [[SetPasswordViewController alloc] init];
    [self.navigationController pushViewController:setPasswordVC animated:YES];
}

- (void)passwordSwitch {
    PasswordSwitchViewController *passwordSwitchVC = [[PasswordSwitchViewController alloc] init];
    [self.navigationController pushViewController:passwordSwitchVC animated:YES];
}

- (void)feedback {
    FeedbackViewController *feedbackVC = [[FeedbackViewController alloc] init];
    [self.navigationController pushViewController:feedbackVC animated:YES];
}

- (void)aboutUs {
    AboutUsViewController *aboutUsVC = [[AboutUsViewController alloc] init];
    [self.navigationController pushViewController:aboutUsVC animated:YES];
}

- (void)clearInfo {
    
}
//- (UITableView *)tableView {
//    if (!_tableView) {
//        _tableView = [[UITableView alloc] initWithFrame:CRM(2 / 5 * PROPORTION_W, PROPORTION_H * 0.1, 0.6 * PROPORTION_W, PROPORTION_H * 0.75)];
//        _tableView.delegate = self;
//        _tableView.dataSource = self;
//        _tableView.rowHeight = PROPORTION_H / 10;
//        _tableView.backgroundColor = [UIColor yellowColor];
//    }
//    return _tableView;
//}

=======
>>>>>>> 3af5984bb38fe08b215b67d9275d8a5c220e779d
@end
